package com.ailot.cloud.mall.controller;

import com.ailot.cloud.base.common.dto.Result;
import com.ailot.cloud.base.log.annotation.Oplog;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
import com.ailot.cloud.mall.entity.GoodsEvaluation;
import com.ailot.cloud.mall.service.GoodsEvaluationService;

/**
 * 商品评价表
 * @Author ailot
 * @create 2025-01-06
 */

@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/goodsevaluation")
public class GoodsEvaluationController {

    private final GoodsEvaluationService goodsEvaluationService;

    /**
     *   分页
     */
    @GetMapping("/page")
    @PreAuthorize("hasAuthority('mall:goodsevaluation:page')")
    public Page<GoodsEvaluation> getGoodsEvaluationPage(Page<GoodsEvaluation> page, GoodsEvaluation goodsEvaluation) {
        return goodsEvaluationService.page(page, Wrappers.query(goodsEvaluation));
    }

    /**
     * 新增
     */
    @Oplog("新增")
    @PostMapping
    @PreAuthorize("hasAuthority('mall:goodsevaluation:add')")
    public Boolean save(@Valid @RequestBody GoodsEvaluation goodsEvaluation) {
        return goodsEvaluationService.save(goodsEvaluation);
    }

    /**
     * 修改
     */
    @Oplog("修改")
    @PutMapping
    @PreAuthorize("hasAuthority('mall:goodsevaluation:edit')")
    public Boolean update(@Valid @RequestBody GoodsEvaluation goodsEvaluation) {
        return goodsEvaluationService.updateById(goodsEvaluation);
    }

    /**
     *  删除
     */
    @Oplog("删除")
    @DeleteMapping("/{id}")
    @PreAuthorize("hasAuthority('mall:goodsevaluation:del')")
    public Result delete(@PathVariable String id) {
        return Result.success(goodsEvaluationService.removeById(id));
    }


}
